<?php
namespace XWAM\Addon\PXCallSystem\Controller;
/**
 * 权限控制器
 *
 * @author Alen
 * @since 1.0 2014-6-13 by sutroon
 */
class PermissionController extends AppbaseController {

    //put your code here
    public function get_json() {
        $str = sofunc_get_tree_json('tuser_permission');
        $this->ajaxReturn($str);
    }

    public function user_edit() {
        $uid = I('id');
        if (!$uid) {
            $uid = $this->loginData['id'];
        }
        $this->assign('uid', $uid);
        $rules = M('tuser_member')->where('id=' . $uid)->getField('permissionRule');
        $this->itemTreeList('tuser_permission', "parentID={0}", 0, array('ORDERBY' => 'id asc', 'CHECKBOX' => true, 'VALUES' => $rules));
    }

    public function user_edit_save() {
        $ids = I('ids');
        $uid = I('uid');
        if (!$uid || !$ids) {
            $this->ajaxMsg(false, '参数有误');
        }
        $result = M('tuser_member')->where('id=' . $uid)->setField('permissionRule', implode(',', $ids));
        $this->ajaxMsg($result, '保存{%}');
    }

    public function reset_user_permission() {
        $uid = I('uid');
        if (!$uid) {
            $this->ajaxMsg(false, '参数有误');
        }
        $result = M('tuser_member')->where('id=' . $uid)->setField('permissionRule', sofn_get_config('USER.PERMISSION.ADMIN'));
        $this->ajaxMsg($result, '保存{%}');
    }

}
